package com.yc.pro3.controllers;

import ch.qos.logback.classic.Logger;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.Set;

@RestController
@Log
public class HelloController {
    @GetMapping("/hello")
    @SentinelResource("helloWorld")
    public String helloWorld(){
        return "hello world";
    }

    public Set<Thread> set = new HashSet<>();

    @GetMapping("/hello2")
    @SentinelResource("helloWorld2")
    public String helloWorld2() throws InterruptedException {
        Thread thread = Thread.currentThread();
        set.add(thread);
        log.info("线程数为:"+set.size()+"当前线程编号为:"+thread.getId());
        Thread.sleep(1000);
        return thread.toString();
    }
}
